package thread.codesynchronized;

public class TicketTask implements Runnable {
    int ticket = 10000;

    @Override
    public void run() {
        sale();
    }

    public synchronized void sale() {
        while (true) {
            if (ticket <= 0) {
                System.out.println("票卖完了...");
                break;
            } else {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 恭喜你买到票，票号为" + ticket);
                ticket--;
            }
        }
    }
}
